package com.yuju.controller.order;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.Result;
import com.yuju.common.fileld.validator.FieldValidator;
import com.yuju.controller.base.BaseController;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.rpt.enums.BusinessDailyReturnCodeEnum;
import com.yuju.rpt.model.BusinessDailyModel;
import com.yuju.rpt.service.IBusinessDailyService;
import com.yuju.util.Utils;
import com.yuju.vo.rpt.BusinessDailyVO;

/**
 * 类名：BusinessDailyController  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2018年1月31日 下午6:15:08  <br />
 * @version : 1.1 <br />
 */
@Controller
@RequestMapping("businessDaily")
public class BusinessDailyController extends BaseController<BusinessDailyVO, BusinessDailyModel> {
	
	@Autowired
	private IBusinessDailyService businessDailyService;
	
	/**
	 * 功能：查找营业日报<br/>
	 *
	 * @author jiaokn
	 * @Date 2017年12月11日 下午4:56:11 <br/>
	 */
	@RequestMapping("get")
	@ResponseBody
	public Result get(@RequestBody JSONObject obj){
		BusinessDailyVO businessDailyVO = obj.toJavaObject(BusinessDailyVO.class);
		Map<String, String> fail = FieldValidator.validateAll(businessDailyVO, "get", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		BusinessDailyModel model = businessDailyService.find(convert(businessDailyVO));
		Result result = new Result();
		if(Utils.isNotNull(model)){
			result.setData(model);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(BusinessDailyReturnCodeEnum.BUSENESSDAILY_GET_SUCCESS.getCode());
			result.setReturnMsg(BusinessDailyReturnCodeEnum.BUSENESSDAILY_GET_SUCCESS.getDesc());
		}else{
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(BusinessDailyReturnCodeEnum.BUSENESSDAILY_GET_FAILURE.getCode());
			result.setReturnMsg(BusinessDailyReturnCodeEnum.BUSENESSDAILY_GET_FAILURE.getDesc());
		}
		return result;
	}
	
}
